<script type="text/javascript">
$(document).ready(function() {
    var initial_width;
    //初始化完成
    $('#cgsnapshot_table').jqGrid({
        url: '/grid_cgsnapshot',
        styleUI: 'Bootstrap',
        datatype: 'json',
        mtype: 'POST',
        colNames: ['编号', '[["label name"|translate]]', "[[ 'home Consistency group'|translate ]]", "[['label owner'|translate]]",
            '[["label Creation time"|translate]]', '[["label operation"|translate]]'
        ],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 3,
            hidden: true
        }, {
            name: 'name',
            index: 'name',
            width: 8,
            formatter: function(cellvalue, option, row) {
                var colname = new Array("id", "name");
                return '<a href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cellvalue + '</a>';
               // return '<a href="#" onclick="showmessage(\'' + option.gid + '\',\'' + colname + '\')">' + cellvalue + '</a>';
            },
            unformat: function(cellvalue) {
                return cellvalue;
            }
        }, {
            name: 'CGSnapName',
            index: 'CGSnapName',
            width: 8
        }, {
            name: 'username',
            index: 'username',
            width: 6
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 8
        }, {
            name: 'service',
            index: 'service',
            width: 6,
            sortable: false,
            detailHidden:true,
            formatter: function(cell,option,row) {
                var html = '';
//                html += '<button title="克隆存储卷" class="btn btn-blue btn-sm" onclick=confirm_cgsnapshot_clone(' + row[0] + ',"' + row[1] + '")>克隆存储卷</button>';
                html += '<button title="回滚" class="btn btn-blue btn-sm" onclick=confirm_cgsnapshot_rollback(' + row[0] + ',"' + row[1] + '")>回滚</button>';
                html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue btn-sm" onclick=confirm_cgsnapshot_delete(' + row[0] + ',"' + row[1] + '")>删除</button>';
                return html;
            }
        }],
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        altclass: 'ui-priority-secondary',
        altRows: true,
        autowidth: true,
        shrinkToFit: true,
        beforeSelectRow:function(rowid, e) {
            if($(e.target).is('input')) {
                return true;
            }
            return false;
        },
        gridComplete: function() {
            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
        },
        resizeStart: function() {
            initial_width = $(this).width();
        },
        resizeStop: function() {
            return
        }
    });
});

function cgsnapshot_delete(cgsnapshot_id) {
    $.post("/cgsnapshot_delete", {
            'id': cgsnapshot_id
        },
        function(data) {
            if (data.reply.is_success) {
                $('#cgsnapshot_table').trigger("reloadGrid");
                SelfAlert("删除成功", "完成提示");
            } else {
                error = data.reply.error;
                SelfAlert("删除失败：" + error)
            }
        });
}

function confirm_cgsnapshot_delete(cgsnapshot_id, cgsnapshot_name) {
    msg = '确认删除卷组快照?';
    SelfConfirm(msg, cgsnapshot_delete, cgsnapshot_id, "删除提示");
}

function cgsnapshot_rollback(cgsnapshot_id) {
    $.post("/cgsnapshot_rollback", {
            'id': cgsnapshot_id
        },
        function(data) {
            if (data.reply.is_success) {
                $('#cgsnapshot_table').trigger("reloadGrid");
                SelfAlert("回滚卷组快照完成", "完成提示");
            } else {
                error = data.reply.error;
                SelfAlert("回滚卷组快照失败：" + error)
            }
        });
}

function confirm_cgsnapshot_rollback(cgsnapshot_id, cgsnapshot_name) {
    msg = "确认回滚卷组快照？"
    SelfConfirm(msg, cgsnapshot_rollback, cgsnapshot_id, "确认提示");
}

function confirm_cgsnapshot_clone(cgsnapshot_id, cgsnapshot_name) {
    angular.element('#cgsnapshot_controller').scope().open("/cgsnapshot_clone?id=" + cgsnapshot_id);
}
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>卷组快照</h3>
            <p>卷组快照管理</p>
        </div>
        <div class="grid-tools">
            <div class="grid-operate pull-left">
                <button class="btn btn-blue" type="button" id="cgsnapshot_controller" ng-controller="CGSnapshotModalCtrl" ng-hide="true">创建</button>
            </div>
        </div>
        <div class="grid-body" id="gridttt">
            <table id="cgsnapshot_table"></table>
        </div>
    </div>
</div>
<!-- <div class="panel panel-default">
        <div class="panel-body">
                <button id="cgsnapshot_controller" ng-controller="CGSnapshotModalCtrl" ng-hide="true"></button>
                <div class="item_toolsbar">
                        <span class="message_img">&nbsp;</span> 
                </div>
                <div id="div_cgsnapshot_table" class='tab_warp'>
                    <table id="cgsnapshot_table"></table>
                </div>
        </div> panel-body
</div>
 -->
